package com.example.securitydemo1.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Created with IntelliJ IDEA.
 * ClassName: SecurityConfig
 * Package: com.example.securitydemo1.config
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-05-29
 * Time: 12:14
 */

//@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //inMemoryAuthentication()内存中身份验证 把用户名密码放到内存当中
        //加上 用户名 密码 角色
        //对密码进行加密
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        //加密
        String password = passwordEncoder.encode("123");
        //加密之后 会用到PasswordEncoder接口
        auth.inMemoryAuthentication().withUser("lucy").password(password).roles("admin");
    }

    //加密之后 会用到PasswordEncoder接口
    @Bean
    PasswordEncoder password(){
        //BCryptPasswordEncoder()这个实现类的接口是PasswordEncoder
        return new BCryptPasswordEncoder();
    }
}
